package com.zang.blogz.controller;

import com.zang.blogz.annotation.OptLog;
import com.zang.blogz.constant.OptTypeConstant;
import com.zang.blogz.entity.Photo;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.PhotoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 照片 前端控制器
 * </p>
 *
 * @author 朵橙i
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/blogz/photo")
@Api(tags = "图片模块")
public class PhotoController {

    @Autowired
    private PhotoService photoService;

    @PostMapping("/admin/savePhoto")
    @ApiOperation(value = "保存照片", notes = "保存照片")
    @OptLog(optType = OptTypeConstant.SAVE)
    public Result<Photo> savePhoto(@RequestBody Photo photo){

        return photoService.savePhoto(photo);
    }

    @DeleteMapping("/admin/deletePhoto")
    @ApiOperation(value = "删除照片", notes = "删除照片")
    @OptLog(optType = OptTypeConstant.REMOVE)
    public Result<String> deletePhoto(@RequestParam(value = "photoId") Integer photoId){

        return photoService.deletePhoto(photoId);
    }

    @PostMapping("/admin/movePhotos")
    @ApiOperation(value = "批量移动照片" , notes = "批量移动照片")
    @OptLog(optType = OptTypeConstant.UPDATE)
    public Result<String> movePhotos(@RequestParam(value = "ids") String ids,
                                          @RequestParam(value = "albumId") Integer albumId){

        return photoService.movePhotos(ids, albumId);
    }

}
